package com.job.GaoYuXuan.Homework0702;

import java.util.Scanner;

/**
 * @author 盖
 * @version 1.0
 * @since 2022-07-02 17:25:07
 */
public class Job0702ThreeGame {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入参与者的个数：");
        int person = input.nextInt();
        int win = winner(person);
        System.out.println("获胜者为：" + win);

    }
    public static int winner(int p){
        int[] person = new int[p];
        for (int i = 0; i < p; i++){
            person[i] = i + 1;
        }
        while(person.length > 3){
            int[] newperson = new int[person.length-1];
            for (int i = 3; i < person.length; i++){
                newperson[i - 3] = person[i];
            }
            newperson[newperson.length - 2] = person[0];
            newperson[newperson.length - 1] = person[1];
            person = newperson;
        }
        return person[1];
    }
}